package com.jiang.daily.Q2785;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/09/11 14:02
 */
class Solution {
    private static final Set<Character> vowels = new HashSet<>(Arrays.asList(
            'a', 'e', 'i', 'o', 'u',
            'A', 'E', 'I', 'O', 'U'));

    public String sortVowels(String s) {
        int[] cnt = new int[58];
        Arrays.fill(cnt, -1);
        for (char c: vowels) {
            cnt[c - 'A'] = 0;
        }

        for (char c: s.toCharArray()) {
            int i = c - 'A';
            if (cnt[i] != -1) {
                cnt[i]++;
            }
        }

        char[] arr = s.toCharArray();
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            if (cnt[arr[i] - 'A'] != -1) {
                while (cnt[index] <= 0) {
                    index++;
                }
                arr[i] = (char)(index + 'A');
                cnt[index]--;
            }
        }

        return new String(arr);
    }

}
